package com.gongfutrip.trans;


import java.io.UnsupportedEncodingException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.gongfutrip.trans.client.BusinesssRequestCode;
import com.gongfutrip.trans.client.ProducerImpl;
import com.gongfutrip.trans.client.common.Message;
import com.gongfutrip.trans.client.common.SendCallback;
import com.gongfutrip.trans.client.common.SendResult;
import com.gongfutrip.trans.client.exception.ClientException;
import com.gongfutrip.trans.remoting.netty.NettyClientConfig;


public class StartProducer {
  private static final Logger logger = LoggerFactory.getLogger(ProducerImpl.class);


  public static void main(String[] args)
      throws UnsupportedEncodingException, ClientException, InterruptedException {

    String addr = "127.0.0.1";
    ProducerImpl producer = new ProducerImpl(new NettyClientConfig(), null);
    for (int i = 0; i < 1000; i++) {
      Message msg = new Message(BusinesssRequestCode.SHOPPINBG, addr + ":8888",
          ("{\"buyerGTPId\":16,\"cacheTime\":2700000,\"groupId\":49,\"roleId\":0,\"sourceType\":\"API\",\"timeout\":20000,\"token\":\"84108111-10c6-49af-b6b4-3a60a0247810\",\"uid\":\"RksVSX7PfZm1yF04adBWYsCD7M4=\",\"useLcc\":false,\"useTeam\":false},{\"buyerCurrency\":\"CNY\",\"dataSourceGTPId\":1024,\"extraInfo\":{\"productCode\":\"TS1700014632\",\"productSource\":\"UTOUR\",\"searchKey\":\"BJSBKK20170509YBKKBJS20170514Y1000\",\"solutionKey\":\"0c7dda08b5df4ac4854c539484e05652\"},\"flights\":[{\"airline\":\"TG\",\"arrivalDate\":\"2017-05-09\",\"arrivalTime\":\"21:15\",\"baseSegments\":[{\"airline\":\"TG\",\"arrival\":\"BKK\",\"arrivalDate\":\"2017-05-09\",\"arrivalTime\":\"21:15\",\"arrivalTimestamp\":1494335700000,\"availabilityCount\":1,\"bookingCode\":\"G\",\"bookingCodeMap\":{\"G\":1},\"cabinClass\":\"ECONOMY\",\"cabinCodeMap\":{},\"changePlane\":false,\"codeShare\":\"N\",\"connection\":false,\"departure\":\"PEK\",\"departureDate\":\"2017-05-09\",\"departureTime\":\"17:05\",\"equipment\":\"773\",\"extInfo\":{},\"fareBasis\":\"YRT\",\"flightNum\":\"615\",\"flightSeq\":\"0\",\"flightTime\":310,\"index\":0,\"lowerBookingCodeMap\":{},\"opFltAirline\":\"\",\"opFltNo\":\"\",\"seqNum\":0,\"terminalDep\":\"3\"}],\"bookingCodeKey\":\"G\",\"departureDate\":\"2017-05-09\",\"departureTime\":\"17:05\",\"destination\":\"BKK\",\"flightType\":\"RT\",\"gds\":\"TEAM\",\"origin\":\"BJS\",\"ruleRefs\":[],\"segmentKey\":\"TG615\",\"segmentType\":\"1\",\"travelTime\":310},{\"airline\":\"TG\",\"arrivalDate\":\"2017-05-14\",\"arrivalTime\":\"15:50\",\"baseSegments\":[{\"airline\":\"TG\",\"arrival\":\"PEK\",\"arrivalDate\":\"2017-05-14\",\"arrivalTime\":\"15:50\",\"arrivalTimestamp\":1494748200000,\"availabilityCount\":1,\"bookingCode\":\"G\",\"bookingCodeMap\":{\"G\":1},\"cabinClass\":\"ECONOMY\",\"cabinCodeMap\":{},\"changePlane\":false,\"codeShare\":\"N\",\"connection\":false,\"departure\":\"BKK\",\"departureDate\":\"2017-05-14\",\"departureTime\":\"10:10\",\"equipment\":\"773\",\"extInfo\":{},\"fareBasis\":\"YRT\",\"flightNum\":\"614\",\"flightSeq\":\"0\",\"flightTime\":280,\"index\":0,\"lowerBookingCodeMap\":{},\"opFltAirline\":\"\",\"opFltNo\":\"\",\"seqNum\":0,\"terminalArr\":\"3\"}],\"bookingCodeKey\":\"G\",\"departureDate\":\"2017-05-14\",\"departureTime\":\"10:10\",\"destination\":\"BJS\",\"flightType\":\"RT\",\"gds\":\"TEAM\",\"origin\":\"BKK\",\"ruleRefs\":[],\"segmentKey\":\"TG614\",\"segmentType\":\"2\",\"travelTime\":280}],\"hasPriced\":false,\"latestTktTime\":\"2017-05-04 17:05:00\",\"passengers\":[\"ADT\"],\"platingCarrier\":\"TG\",\"prices\":{\"ADT\":{\"buyerCurrency\":\"CNY\",\"buyerDistributionFee\":0,\"buyerMarkup\":0,\"buyerOtherCharge\":0,\"buyerPlatformServiceFee\":0,\"buyerPriceAdjustment\":0,\"buyerQcharge\":0,\"buyerServiceFee\":0,\"buyerTKTFee\":0.0,\"buyerTaxes\":250.0,\"buyerTicketPrice\":2650.0,\"buyerTotalPrice\":2900.0,\"footmark\":[{\"key\":\"step1.1\",\"value\":\"Fare LCF exchange: 1325 x 1 = 1325<br>Q LCF exchange: 0 x 1 = 0<br>Total LCF combine: 1325 + 0 = 1325\"},{\"key\":\"step1.2\",\"value\":\"Fare LCF exchange: 1325 x 1 = 1325<br>Q LCF exchange: 0 x 1 = 0<br>Total LCF combine: 1325 + 0 = 1325\"},{\"key\":\"step2\",\"value\":\"merge ( TLCF_?{1:1325, 2:1325} ) =  TLCF{2650}<br>round_fare ( TLCF{2650} ,  POC{CNY} ,  REGION{Worldwide} ,  COUNTRY{CN} ) =  TLCF{2650}<br>exchange_gds ( POC{CNY} ,  POS{CNY} ,  GDS{1T} ,  GTP{GTP} ) =  EXC_GDS{1}<br>TLCF{2650}  *  EXC_GDS{1}  =  BFARE{2650}<br>round_fare ( BFARE{2650} ,  POS{CNY} ,  REGION{Worldwide} ,  COUNTRY{CN} ) =  SUPPLIER_FARE{2650}<br>merge ( TAX_DETAIL_?{PK:250} ) =  SUPPLIER_TAX{250}<br>Supplier price merge: supplierFare:2650 + supplierTax:250 + supplierTKTFee:0 = 2900\"},{\"key\":\"step3\",\"value\":\"Fare s2b exchange: 2650 x 1 >> 2650<br>Tax s2b exchange: 250 x 1 >> 250<br>TktFee s2b exchange: 0 x 1 >> 0<br>Fare buyer merge: buyerFare:2650 + buyerTaxes:250 + buyerTKTFee:0 = 2900\"},{\"key\":\"farebasis\",\"value\":\"YRT\"},{\"key\":\"basic\",\"value\":\"fc:null<br>(p)p2s.GDS:CNY>CNY:1T/2017-04-18/1<br>s2b.bank:CNY>CNY:null/2017-04-18 19:51:37.3/1<br>roe:1<br>s.taxes:250<br>PK:250<br>nuc1.fare:1325<br>nuc1.Q:0<br>nuc2.fare:1325<br>nuc2.Q:0<br>\"},{\"key\":\"policy\",\"value\":\"\"},{\"key\":\"datasource\",\"value\":\"team\"},{\"key\":\"tktpcc\",\"value\":\"team\"},{\"key\":\"fareSource\"},{\"key\":\"supplierCode\",\"value\":\"BJS-TEAM-1T\"},{\"key\":\"markup\",\"value\":\"----\"}],\"p2sGDSRate\":1,\"priceCalculation\":{\"nUCBasePrices\":[1325.00,1325.00],\"nUCQCharges\":[0,0],\"nUCTotalPrice\":2900.00,\"pOCCurrency\":\"CNY\",\"rOE\":1,\"supplierDetailTaxes\":{},\"supplierFaceValue\":2650.00},\"s2bBankRate\":1,\"supplierCurrency\":\"CNY\",\"supplierFaceTaxValue\":250.00,\"supplierFaceValue\":2650.00,\"supplierServiceFee\":0,\"supplierTKTFee\":0,\"supplierTaxes\":250.00,\"supplierTicketPrice\":2650.0,\"supplierTotalPrice\":2900.00,\"taxMap\":{\"PK\":250.00}}},\"tKTSupplierGTPId\":1024},{\"needAVGTPIds\":[1024],\"needPricingGTPIds\":[1024]},\"ALL\""
              + i).getBytes("utf-8"));
      // SendResult sendResult = producer.sendSync(msg);
      // logger.info(sendResult.toString());
      //
      producer.sendAsync(msg, new SendCallback() {

        @Override
        public void onSuccess(SendResult sendResult) {
          logger.info("发送给服务端完成收到结果：" + sendResult.toString());
        }

        @Override
        public void onException(Throwable e) {
          logger.info(e.getMessage());
        }
      });
    }
  }
}
